package com.ktjy.thymeleaf.controller;

import com.ktjy.thymeleaf.entity.SysUser;
import com.ktjy.thymeleaf.service.SysUserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Date;

@Controller
public class ExampleController {
    @Resource
    private SysUserService service;

    @GetMapping(value = "/hello/{id}")
    public String getUser(@PathVariable("id")Long id, Model model){
        SysUser sysUser=service.getUser(id);
        model.addAttribute("user",sysUser);
        return "/hello";
    }

    @GetMapping(value = "/string")
    public String getString(Model model, HttpServletRequest request){
        model.addAttribute("userName","ktjy");
        request.setAttribute("test","request");
        request.getSession().setAttribute("test","session");
        model.addAttribute("date",new Date());
        return "/hello";
    }

    @GetMapping(value = "/inline")
    public String inline(Model model){
        model.addAttribute("userName","ktjiaoyu");
        return "/hello";
    }
}
